package apiday08.reflect;

import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo4 {
    public static void main(String[] args) throws Exception {
        Class cls = Class.forName("apiday08.reflect.Person");
        Object obj = cls.newInstance();

        Method method = cls.getMethod("sayHello");
        method.invoke(obj);

        Scanner sc = new Scanner(System.in);
        String str = "apiday08.reflect.";
        System.out.println("请输入类名：");
        String className = sc.nextLine();
        System.out.println("请输入方法名：");
        String methodName = sc.nextLine();
        Class cls1 = Class.forName(str+className);
        Object obj1 = cls1.newInstance();
        Method method1 = cls1.getMethod(methodName);
        method1.invoke(obj1);

    }
}
